
log using "$plots/Event_study_log.smcl", replace
display "`c(current_time)' `c(current_date)'"


local window_begin = 15
local window_end = 43

// Main specification: Chaisemartin on county level and clusters on the state level
foreach a of numlist 1 2 3 4{
use "$altered_data/event_study_vaccination.dta", clear
keep if date >= td(12jul2021) & date <= td(04oct2021)
gen vac_rate_lag14 = cum_cases_14_lag / pop_total

keep if age == `a'


	if `a' == 1 {
		local header "Age: 5 - 14"
	}
	if `a' == 2 {
		local header "Age: 15 - 34"
	} 
	if `a' == 3 {
		local header "Age: 35 - 59"
	} 
	if `a' == 4 {
		local header "Age: 60+"
	}

	
did_multiplegt cases_melde RS date treated, robust_dynamic controls(cases_cum14 vac_rate_lag14 mob*)  placebo(`window_begin') dynamic(`window_end') breps(100) cluster(idbundesland) weight(pop_total) save_results("$altered_data/did_multiplegt_main_`a'.dta")

use "$altered_data/did_multiplegt_main_`a'.dta", clear
scatter treatment_effect treatment_effect_lower_95CI treatment_effect_upper_95CI time_to_treatment, ///
c(l l l) cmissing(n n n) msym(i i i) lcolor(gs4 gs10 gs10) lpattern(solid solid solid) lwidth(thick medthick medthick) ///
yline(0, lcolor(black)) xline(0, lcolor(black)) ///
legend(order(1  2) label(1 "Point estimates") label(2 "95% CI") cols(2)) ///
subtitle("", size(vsmall) j(left) pos(11)) ///
ylabel(-150(50)150,nogrid angle(horizontal) labsize(small)) graphregion(color(white)) ///
xtitle("Days relative to end of summer break") xlab(-`window_begin'(5)`window_end')  name("did_gt_`a'", replace)  title("`header'", color(black))  
}

grc1leg did_gt_1 did_gt_2 did_gt_3 did_gt_4, graphregion(color(white)) ycommon
graph export "${plots}chaise_main.png", replace width(3000)

display "`c(current_time)' `c(current_date)'"


// Robustness 1: Standard Errors clustered on the county level
foreach a of numlist 1 2 3 4{
use "$altered_data/event_study_vaccination.dta", clear
keep if date >= td(12jul2021) & date <= td(04oct2021)
gen vac_rate_lag14 = cum_cases_14_lag / pop_total

keep if age == `a'


	if `a' == 1 {
		local header "Age: 5 - 14"
	}
	if `a' == 2 {
		local header "Age: 15 - 34"
	} 
	if `a' == 3 {
		local header "Age: 35 - 59"
	} 
	if `a' == 4 {
		local header "Age: 60+"
	}

	
did_multiplegt cases_melde RS date treated, robust_dynamic controls(cases_cum14 vac_rate_lag14 mob*)  placebo(`window_begin') dynamic(`window_end') breps(100) cluster(RS) weight(pop_total) save_results("$altered_data/did_multiplegt_cluster_county_`a'.dta")

use "$altered_data/did_multiplegt_cluster_county_`a'.dta", clear
scatter treatment_effect treatment_effect_lower_95CI treatment_effect_upper_95CI time_to_treatment, ///
c(l l l) cmissing(n n n) msym(i i i) lcolor(gs4 gs10 gs10) lpattern(solid solid solid) lwidth(thick medthick medthick) ///
yline(0, lcolor(black)) xline(0, lcolor(black)) ///
legend(order(1  2) label(1 "Point estimates") label(2 "95% CI") cols(2)) ///
subtitle("", size(vsmall) j(left) pos(11)) ///
ylabel(-100(25)10,nogrid angle(horizontal) labsize(small)) graphregion(color(white)) ///
xtitle("Days relative to end of summer break") xlab(-`window_begin'(5)`window_end')  name("did_gt_`a'", replace)  title("`header'", color(black))  
}

grc1leg did_gt_1 did_gt_2 did_gt_3 did_gt_4, graphregion(color(white)) ycommon
graph export "${plots}chaise_rob_cluster_county.png", replace width(3000)



display "`c(current_time)' `c(current_date)'"


// Robustness 2: without mobility controls
foreach a of numlist 1 2 3 4{
use "$altered_data/event_study_vaccination.dta", clear
keep if date >= td(12jul2021) & date <= td(04oct2021)
gen vac_rate_lag14 = cum_cases_14_lag / pop_total

keep if age == `a'


	if `a' == 1 {
		local header "Age: 5 - 14"
	}
	if `a' == 2 {
		local header "Age: 15 - 34"
	} 
	if `a' == 3 {
		local header "Age: 35 - 59"
	} 
	if `a' == 4 {
		local header "Age: 60+"
	}

	
did_multiplegt cases_melde RS date treated, robust_dynamic controls(cases_cum14 vac_rate_lag14)  placebo(`window_begin') dynamic(`window_end') breps(100) cluster(idbundesland) weight(pop_total) save_results("$altered_data/did_multiplegt_without_mobil_`a'.dta")

use "$altered_data/did_multiplegt_without_mobil_`a'.dta", clear
scatter treatment_effect treatment_effect_lower_95CI treatment_effect_upper_95CI time_to_treatment, ///
c(l l l) cmissing(n n n) msym(i i i) lcolor(gs4 gs10 gs10) lpattern(solid solid solid) lwidth(thick medthick medthick) ///
yline(0, lcolor(black)) xline(0, lcolor(black)) ///
legend(order(1  2) label(1 "Point estimates") label(2 "95% CI") cols(2)) ///
subtitle("", size(vsmall) j(left) pos(11)) ///
ylabel(-150(50)150,nogrid angle(horizontal) labsize(small)) graphregion(color(white)) ///
xtitle("Days relative to end of summer break") xlab(-`window_begin'(5)`window_end')  name("did_gt_`a'", replace)  title("`header'", color(black))  
}

grc1leg did_gt_1 did_gt_2 did_gt_3 did_gt_4, graphregion(color(white)) ycommon
graph export "${plots}chaise_rob_without_mobil.png", replace width(3000)

display "`c(current_time)' `c(current_date)'"


local window_begin = 15
local window_end = 43

// Robustness 3: without vacination rate as control variable
foreach a of numlist 1 2 3 4{
use "$altered_data/event_study_vaccination.dta", clear
keep if date >= td(12jul2021) & date <= td(04oct2021)

keep if age == `a'


	if `a' == 1 {
		local header "Age: 5 - 14"
	}
	if `a' == 2 {
		local header "Age: 15 - 34"
	} 
	if `a' == 3 {
		local header "Age: 35 - 59"
	} 
	if `a' == 4 {
		local header "Age: 60+"
	}

	
did_multiplegt cases_melde RS date treated, robust_dynamic controls(cases_cum14 mob*)  placebo(`window_begin') dynamic(`window_end') breps(100) cluster(idbundesland) weight(pop_total) save_results("$altered_data/did_multiplegt_`a'.dta")

use "$altered_data/did_multiplegt_`a'.dta", clear
scatter treatment_effect treatment_effect_lower_95CI treatment_effect_upper_95CI time_to_treatment, ///
c(l l l) cmissing(n n n) msym(i i i) lcolor(gs4 gs10 gs10) lpattern(solid solid solid) lwidth(thick medthick medthick) ///
yline(0, lcolor(black)) xline(0, lcolor(black)) ///
legend(order(1  2) label(1 "Point estimates") label(2 "95% CI") cols(2)) ///
subtitle("", size(vsmall) j(left) pos(11)) ///
ylabel(-150(50)150,nogrid angle(horizontal) labsize(small)) graphregion(color(white)) ///
xtitle("Days relative to end of summer break") xlab(-`window_begin'(5)`window_end')  name("did_gt_`a'", replace)  title("`header'", color(black))  
}

grc1leg did_gt_1 did_gt_2 did_gt_3 did_gt_4, graphregion(color(white)) ycommon
graph export "${plots}chaise_rob_wihtout_vac.png", replace width(3000)

display "`c(current_time)' `c(current_date)'"
log close
translate Event_study_log.smcl Event_study_log.pdf
exit

